<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Site/classes/PhpFox_ComponentContactUs.class.php, $Author:  $ */



/** Component for sending emails for admin
 * @version $Id: PhpFox_ComponentContactUs.class.php 387 2008-03-03 12:48:32Z phpfoxsv $
 * @package module.site
 *
 */
class PhpFox_Mod_Site_ComponentContactUs extends BaseComponent
{
    function process()
    {
        $oReq = &App::getRequest();
        $oSrvSec = &App::getModuleService('Account', 'Security');
        $oTpl = &$this->_oModule->getTemplate();
        App::loadClass('Validator');
        App::loadClass('mail/Mailer');
        $oMailer = &new mail_Mailer();
        
        $this->oDatabase->_delete(App::getT('captcha'), "time < " . (time() - 10 * 60));

        $aFields = array
        (
            'val[user]'  => array('title' => App::format('Mod_Site.your_name'), 'def' => 'required'),
            'val[email]' => array('title' => App::format('Mod_Site.email'), 'def' => 'email'),
            'val[text]'  => array('title' => App::format('Mod_Site.message'), 'def' => 'required'),
        );
        $oValidator = &new Validator($aFields);
        $aValues = array();
        if ($oReq->getAction() == 'send')
        {
            $aValues = $oReq->get('val');
            if (!$oValidator->isValid($oReq->getAll()))
            {
                $this->addErrors($oValidator->getErrors());
            }
            if (!$oSrvSec->checkProtectionCode($oReq->get('sProtCode')))
		    {
		        $this->addErrors(App::format('Mod_Account.error.wrong_code'));
		    }
            if (!count($this->getErrors()))
            {
                $aVars = array();
                $aVars['CONTENT'] = '';
                $aVars['CONTENT'] .= ''. App::format('Mod_Site.full_name') .': '.strip_tags($aValues['user']) . "\n";
                if (!empty($aValues['title']))
                {
                    $aVars['CONTENT'] .= ''. App::format('Mod_Site.subject') .': '.strip_tags($aValues['title']) . "\n";
                }
                if (!empty($aValues['web']) && $aValues['web'] != 'http://')
                {
                    $aVars['CONTENT'] .= ''. App::format('Mod_Site.website') .': '.strip_tags($aValues['web']) . "\n";
                }
                $aVars['CONTENT'] .= ''. App::format('Mod_Site.email') .': '.strip_tags($aValues['email']) . "\n";
                $aVars['CONTENT'] .= ''. App::format('Mod_Site.message') .': '.strip_tags($aValues['text']) . "\n";
				$aVars['HEADER_FROM_USER'] = $aValues['user'];
               	$aVars['HEADER_FROM_EMAIL'] = $aValues['email'];
                
                $aEmails = split(',', App::getSetting('contact_us_emails'));
                foreach ($aEmails as $sEmail) 
                {
                	$oMailer->send('email_blank', $sEmail, 'Contact Info: '.$aValues['title'], $aVars);            	
                }
                App::gotoUrl('public.contact-us', array(), App::format('Mod_Site.info.email_sended'), false, 'contact');
            }
        }

        $oTpl->assignSrc('sValidatorJs', $oValidator->makeJS('document.getElementById(\'submit_form\')', false));
        $oTpl->assignSrc('sValidatorMess', $oValidator->makeJsMess());
        $oTpl->assign(array(
            'aValues' => $aValues,
            'aErrors' => $this->getErrors()
        ));
        return $oTpl->fetch('ContactUs.html');
    }
}
?>